﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<UserControl x:Class="System.Windows.Controls.Samples.FlexibleTemplateSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:System.Windows.Controls.Samples"
    xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0">
            <ContentControl Content="TreeMap using ItemDefinitionSelector" Style="{StaticResource Header}" />
            <TextBlock Style="{StaticResource Information}">
                This sample shows how an ItemDefinitionSelector can be used in the TreeMap control to customize its appearance.  In 
                the example below each level has a different DataTemplate.
            </TextBlock>
            <TextBlock Style="{StaticResource Information}" FontSize="9">
                The statistical data used for this demonstration is (c) Copyright 2008 from http://www.hockeydb.com.
            </TextBlock>
        </StackPanel>
        <datavis:TreeMap x:Name="treeMapControl" Grid.Row="1">
            <datavis:TreeMap.ItemDefinitionSelector>
                <local:AlternatingItemDefinitionSelector>
                    <datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="5,20,5,5">
                        <DataTemplate>
                            <Border Background="#fff0c0c0" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}">
                                <TextBlock Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" TextAlignment="Center" />
                            </Border>
                        </DataTemplate>
                    </datavis:TreeMapItemDefinition>

                    <datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="20,5,5,5">
                        <DataTemplate>
                            <Border Background="#ffc0f0c0" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}">
                                <layoutToolkit:LayoutTransformer>
                                    <layoutToolkit:LayoutTransformer.LayoutTransform>
                                        <RotateTransform Angle="-90" />
                                    </layoutToolkit:LayoutTransformer.LayoutTransform>
                                    <TextBlock x:Name="textBlk" Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" RenderTransformOrigin="0,1" VerticalAlignment="Top">
                                    </TextBlock>
                                </layoutToolkit:LayoutTransformer>
                            </Border>
                        </DataTemplate>
                    </datavis:TreeMapItemDefinition>

                    <datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="5,20,5,5">
                        <DataTemplate>
                            <Border Background="#ffc0c0f0" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}">
                                <TextBlock Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" />
                            </Border>
                        </DataTemplate>
                    </datavis:TreeMapItemDefinition>

                    <datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="0">
                        <DataTemplate>
                            <Border Background="#FFEEE0AA" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}">
                                <TextBlock Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Center" />
                            </Border>
                        </DataTemplate>
                    </datavis:TreeMapItemDefinition>

                </local:AlternatingItemDefinitionSelector>
            </datavis:TreeMap.ItemDefinitionSelector>
        </datavis:TreeMap>

        <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="FlexibleTemplateSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;UserControl x:Class="System.Windows.Controls.Samples.FlexibleTemplateSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:System.Windows.Controls.Samples"
    xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"&gt;

    &lt;Grid&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height="Auto"/&gt;
            &lt;RowDefinition Height="*"/&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;StackPanel Grid.Row="0"&gt;
            &lt;ContentControl Content="TreeMap using ItemDefinitionSelector" Style="{StaticResource Header}" /&gt;
            &lt;TextBlock Style="{StaticResource Information}"&gt;
                This sample shows how an ItemDefinitionSelector can be used in the TreeMap control to customize its appearance.  In 
                the example below each level has a different DataTemplate.
            &lt;/TextBlock&gt;
            &lt;TextBlock Style="{StaticResource Information}" FontSize="9"&gt;
                The statistical data used for this demonstration is (c) Copyright 2008 from http://www.hockeydb.com.
            &lt;/TextBlock&gt;
        &lt;/StackPanel&gt;
        &lt;datavis:TreeMap x:Name="treeMapControl" Grid.Row="1"&gt;
            &lt;datavis:TreeMap.ItemDefinitionSelector&gt;
                &lt;local:AlternatingItemDefinitionSelector&gt;
                    &lt;datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="5,20,5,5"&gt;
                        &lt;DataTemplate&gt;
                            &lt;Border Background="#fff0c0c0" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}"&gt;
                                &lt;TextBlock Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" TextAlignment="Center" /&gt;
                            &lt;/Border&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/datavis:TreeMapItemDefinition&gt;

                    &lt;datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="20,5,5,5"&gt;
                        &lt;DataTemplate&gt;
                            &lt;Border Background="#ffc0f0c0" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}"&gt;
                                &lt;layoutToolkit:LayoutTransformer&gt;
                                    &lt;layoutToolkit:LayoutTransformer.LayoutTransform&gt;
                                        &lt;RotateTransform Angle="-90" /&gt;
                                    &lt;/layoutToolkit:LayoutTransformer.LayoutTransform&gt;
                                    &lt;TextBlock x:Name="textBlk" Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" RenderTransformOrigin="0,1" VerticalAlignment="Top"&gt;
                                    &lt;/TextBlock&gt;
                                &lt;/layoutToolkit:LayoutTransformer&gt;
                            &lt;/Border&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/datavis:TreeMapItemDefinition&gt;

                    &lt;datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="5,20,5,5"&gt;
                        &lt;DataTemplate&gt;
                            &lt;Border Background="#ffc0c0f0" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}"&gt;
                                &lt;TextBlock Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" /&gt;
                            &lt;/Border&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/datavis:TreeMapItemDefinition&gt;

                    &lt;datavis:TreeMapItemDefinition ItemsSource="{Binding Children}" ValueBinding="{Binding Points}" ChildItemPadding="0"&gt;
                        &lt;DataTemplate&gt;
                            &lt;Border Background="#FFEEE0AA" BorderBrush="Black" BorderThickness="1" CornerRadius="4" ToolTipService.ToolTip="{Binding ToolTip}"&gt;
                                &lt;TextBlock Text="{Binding Name}" Margin="2,2,0,0" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Center" /&gt;
                            &lt;/Border&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/datavis:TreeMapItemDefinition&gt;

                &lt;/local:AlternatingItemDefinitionSelector&gt;
            &lt;/datavis:TreeMap.ItemDefinitionSelector&gt;
        &lt;/datavis:TreeMap&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="FlexibleTemplateSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.ComponentModel;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample showing how an ItemDefinitionSelector can be used to return a different
    /// template for each level in the tree.
    /// &lt;/summary&gt;
    [Sample("(1)ItemDefinitionSelector", DifficultyLevel.Intermediate)]
    [Category("TreeMap")]
    public partial class FlexibleTemplateSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the FlexibleTemplateSample class.
        /// &lt;/summary&gt;
        public FlexibleTemplateSample()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(FlexibleTemplateSample_Loaded);
        }

        /// &lt;summary&gt;
        /// Loads the XML sample data and populates the TreeMap.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The object where the event handler is attached.&lt;/param&gt;
        /// &lt;param name="e"&gt;The event data.&lt;/param&gt;
        private void FlexibleTemplateSample_Loaded(object sender, RoutedEventArgs e)
        {
            // Sample browser-specific layout change
            SampleHelpers.ChangeSampleAlignmentToStretch(this);

            treeMapControl.ItemsSource = DataHelper.LoadDefaultFile();
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="NhlNode.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Represents the statistics for a team, division, conference, or the league as a whole.
    /// &lt;/summary&gt;
    public class NhlNode
    {
        /// &lt;summary&gt;
        /// Gets or sets a value representing the rank of the node in its level (team, division, etc).
        /// &lt;/summary&gt;
        public int Rank { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the name of the entity (team, division, etc).
        /// &lt;/summary&gt;
        public string Name { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the number of points either for a single team in the case of a leaf, 
        /// or the aggregate sum of the children for a parent node.
        /// &lt;/summary&gt;
        public int Points { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the number of wins either for a single team in the case of a leaf, 
        /// or the aggregate sum of the children for a parent node.
        /// &lt;/summary&gt;
        public int Wins { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the number of losses either for a single team in the case of a leaf, 
        /// or the aggregate sum of the children for a parent node.
        /// &lt;/summary&gt;
        public int Losses { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the number of goals earned in the season either for a single team in the case of a leaf, 
        /// or the aggregate sum of the children for a parent node.
        /// &lt;/summary&gt;
        public int GoalsFor { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the number of goals against accrued either for a single team in the case of a leaf, 
        /// or the aggregate sum of the children for a parent node.
        /// &lt;/summary&gt;
        public int GoalsAgainst { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the number of penalty minutes accrued either for a single team in the case of a leaf, 
        /// or the aggregate sum of the children for a parent node.
        /// &lt;/summary&gt;
        public int PenaltyMinutes { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets a value representing the children of this division, conference, or league. Empty for teams.
        /// &lt;/summary&gt;
        [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Simplifies samples.")]
        public IList&lt;NhlNode&gt; Children { get; set; }

        /// &lt;summary&gt;
        /// Gets the desired tooltip content.
        /// &lt;/summary&gt;
        public string ToolTip
        {
            get
            {
                StringBuilder outStr = new StringBuilder();
                outStr.Append(Name);
                outStr.Append("\nRank: ").Append(Rank);
                outStr.Append("\nPoints: ").Append(Points);
                outStr.Append("\nWins: ").Append(Wins);
                outStr.Append("\nLosses: ").Append(Losses);
                outStr.Append("\nGoals For: ").Append(GoalsFor);
                outStr.Append("\nGoals Against: ").Append(GoalsAgainst);
                outStr.Append("\nPenalty Minutes: ").Append(PenaltyMinutes);

                return outStr.ToString();
            }
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </Grid>
</UserControl>
